<?php
function deathNoticeURL($paper){
    global $db;
    $paper = $db->escape($paper);
    $sql = "SELECT Name, DeathNoticeURL, Web FROM Newspapers WHERE ShortName LIKE '$paper'";
    $result = $db->query($sql);
    if ($db->rowCount($result) != 0) {
        $paperData = $db->fetch($result);
    }else{
        return array();
    }
    $paperURL = $paperData['Web'];
    $paperDataArray = array();
    if (!empty($paperURL)) {
        $paperDataArray = array("name"=>$paperData['Name'], "url"=>$paperURL);
    }
    return $paperDataArray;
}
function getDeathNoticeURL($paper){
    // returns an array with ['name'] and ['url']
    $deathNoticeURL = deathNoticeURL($paper);
    if (empty($deathNoticeURL)) {
        //Try to retrieve the paper name from the flash death notice
        $paper = preg_replace('/DEATH-NOTICE-(.*)-[0-9]*/', '$1', $paper);
        $deathNoticeURL = deathNoticeURL($paper);
    }
    return $deathNoticeURL;
}
?>
